﻿function btn_SendNotification() {
	window.alert("Fonction non implémenté pour la démonstration");
}

function btn_CurrentGameRecap() {	
	window.location = "CurrentGameRecap.html";
}

var myCoord;
var dataEquipes;
var markers=[];
var map;
var mdpPartie = window.localStorage.getItem("passPartie");

function initializeGeoloc(){
	navigator.geolocation.getCurrentPosition(onSuccess, onError);
	function onSuccess(position) {
		myCoord = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
		initializeMap();
    }
    function onError(error) {
        alert('code: '    + error.code    + '\n' +
                'message: ' + error.message + '\n');
    }
}

function initializeMap(){
	var mapOptions = {
		center: myCoord,
		zoom: 14,
		mapTypeId: google.maps.MapTypeId.HYBRID
	};
	map = new google.maps.Map(document.getElementById("map_canvas"),
		mapOptions);
		
	interactionWebService.positionEquipes(onResponsePositionEquipes,
										 onErreurPositionEquipes,
										 mdpPartie);
}

function onResponsePositionEquipes(data) {
	dataEquipes = data;	
	showEquipes();
}

function onErreurPositionEquipes(erreur) {
	alert("Impossible de récupérer les positions des équipes : " + erreur);
}

function showEquipes(){
	var mapBounds = new google.maps.LatLngBounds();
	
	
	mapBounds.extend(myCoord);
	var image = {
		url: '././css/images/iconCoord.png',
		size: new google.maps.Size(48, 48),
		origin: new google.maps.Point(0, 0),
		anchor: new google.maps.Point(24, 48),
		scaledSize: new google.maps.Size(32, 32)
	};
	var m1 = new google.maps.Marker({
	position: myCoord,
	title: 'Ma Position',
	map: map,
	icon : image
	});
	
	
	$.each(dataEquipes, function(i, v) {			
		var coord = new google.maps.LatLng(v.coordx, v.coordy);
		mapBounds.extend(coord);
		var image = {
			url: '././css/images/iconTeam.png',
			size: new google.maps.Size(48, 48),
			origin: new google.maps.Point(0, 0),
			anchor: new google.maps.Point(24, 48),
			scaledSize: new google.maps.Size(32, 32)
		};
		markers[i] = new google.maps.Marker({
		position: coord,
		title: v.nom,
		map: map,
		icon : image
		});	
	});	
	 
	map.fitBounds(mapBounds);
}